package cc.yugu.yhdw.webserver.service.hdw;

import cc.yugu.yhdw.common.constant.CacheKey;
import cc.yugu.yhdw.common.domain.hdw.Cabinet;
import com.whalin.MemCached.MemCachedClient;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * 换电柜业务切面类
 * 
 * @Date:Created in 2018/7/7 9:06
 * @Author:
 * @Modified By: zjn 2018/7/7 9:06
 */ 
@Aspect
@Component
public class CabinetServiceAspect {
    @Autowired
    MemCachedClient memCachedClient;

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.hdw.CabinetService.updateBasic(..))")
    private void updateBasic() {}
    /**
    * 更新
    * 
    * @Param: [joinPoint]
    * @Return: java.lang.Object
    * @Author By: zjn 2018/7/7  9:40
    */ 
    @Around("updateBasic()")
    public Object updateBasic(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        Cabinet terminal = (Cabinet) joinPoint.getArgs()[0];
        String key = CacheKey.key(CacheKey.K_ID_V_CABINET_INFO, terminal.getId());
        memCachedClient.delete(key);
        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.hdw.CabinetService.updateLocation(..))")
    private void updateLocation() {}
    /**
    * 更新地址
    * 
    * @Param: [joinPoint]
    * @Return: java.lang.Object
    * @Author By: zjn 2018/7/7  11:16
    */ 
    @Around("updateLocation()")
    public Object updateLocation(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        Cabinet terminal = (Cabinet) joinPoint.getArgs()[0];
        String key = CacheKey.key(CacheKey.K_ID_V_CABINET_INFO, terminal.getId());
        memCachedClient.delete(key);
        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.hdw.CabinetService.updateImage(..))")
    private void updateImage() {}
    /**
    * 更新图片路径
    * 
    * @Param: [joinPoint]
    * @Return: java.lang.Object
    * @Author By: zjn 2018/7/7  11:17
    */ 
    @Around("updateImage()")
    public Object updateImage(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        Cabinet terminal = (Cabinet) joinPoint.getArgs()[0];
        String key = CacheKey.key(CacheKey.K_ID_V_CABINET_INFO, terminal.getId());
        memCachedClient.delete(key);
        return result;
    }

    @Pointcut("execution(* cc.yugu.yhdw.webserver.service.hdw.CabinetService.delete(..))")
    private void delete() {}
    /**
    * 删除
    * 
    * @Param: [joinPoint]
    * @Return: java.lang.Object
    * @Author By: zjn 2018/7/7  11:30
    */ 
    @Around("delete()")
    public Object delete(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        String key = CacheKey.key(CacheKey.K_ID_V_CABINET_INFO, String.valueOf(joinPoint.getArgs()[0]));
        memCachedClient.delete(key);
        return result;
    }
}
